package com.wanghai.carwashing.api.exception;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * 定义API相关异常
 * @author 王海
 */
public class ApiException extends  Exception{
    // 错误代码
    private int code;
    // 错误描述
    private String desc;
    //状态码
    private int statusCode;
    
    public static final ApiException UNKNOWN_V1_ERROR = new ApiException(999, "未知错误", 400);
    
    public static final ApiException NEED_PERMISSION = new ApiException(1000, "需要权限", 403);
    
    public static final ApiException URI_NOT_FOUND = new ApiException(1001, "你访问的资源不存在", 404);
    
    public static final ApiException MISSING_ARGS = new ApiException(1002, "参数不全", 400);
    
    public static final ApiException ERROR_ARGS = new ApiException(1003, "参数错误", 400);
    
    public static final ApiException IMAGE_TOO_LARGE = new ApiException(1004, "上传的图片太大", 400);
    
    public static final ApiException CAPTCHA_ERROR = new ApiException(1005, "验证码错误", 400);

    public ApiException() {
        
    }
    
    public ApiException(int code, String desc, int statusCode) {
        this.code = code;
        this.desc = desc;
        this.statusCode = statusCode;
    }

    @JSONField
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
    @JSONField
    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
     @JSONField
    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    @Override
    public String toString() {
        return "ApiException{" + "code=" + code + ", desc=" + desc + ", statusCode=" + statusCode + '}';
    }
}
